﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Input;
using WCYCReader.Utility;
using WCYCReader.Pages;

namespace WCYCReader.UserControls
{
    public partial class BackgroundControl : UserControl
    {

        private bool isNew = false;
        private BookReaderPage bookReaderPage;
        public BackgroundControl()
        {
            InitializeComponent();
        }

        public BackgroundControl(BookReaderPage bookReaderPage, bool isNew = true)
            : this()
        {
            this.isNew = true;
            this.bookReaderPage = bookReaderPage;
        }

        private void UpdateBackgroundPanel(int num)
        {
            if (!this.isNew)
                this.PopupBackgroundPanel(num);
            else
                this.bookReaderPage.BookReader_BackgroundMenu(num);
        }

        private void Background_ManipulationStarted1(object sender, ManipulationStartedEventArgs e)
        {
            this.Background_NightMode();
            //this.PopupBackgroundPanel(0);
            this.UpdateBackgroundPanel(0);
        }

        private void Background_ManipulationStarted2(object sender, ManipulationStartedEventArgs e)
        {
            this.Background_NightMode();
            //this.PopupBackgroundPanel(1);
            this.UpdateBackgroundPanel(1);
        }

        private void Background_ManipulationStarted3(object sender, ManipulationStartedEventArgs e)
        {
            this.Background_NightMode();
            //this.PopupBackgroundPanel(2);
            this.UpdateBackgroundPanel(2);
        }

        private void Background_ManipulationStarted4(object sender, ManipulationStartedEventArgs e)
        {
            this.Background_NightMode();
            //this.PopupBackgroundPanel(3);
            this.UpdateBackgroundPanel(3);
        }

        private void Background_NightMode()
        {
            if ((bool)SettingHelper.GetValueFromSettings("BookReader_NightMode"))
            {
                SettingHelper.SaveInToSettings("BookReader_NightMode", false);
            }
        }
    }
}
